
package UVA;
import java.util.Scanner;
import java.util.Arrays;
/**
 *
 * @author Josh Lear
 * @date 6/8/2014
 * @Problem backtracking
 * @TODO implement with DP maybe. Wasn't necessary here.
 */
public class UVA_624 {
    public static boolean found;
    public static int maxFound;
    public static int max;
    public static int[] nums;
    public static boolean[] keys;
public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    while(sc.hasNext()){
        maxFound = -1;
        found = false;
        max = sc.nextInt();
        int n = sc.nextInt();
        nums = new int[n];
        for(int i =0 ; i < n; i++){
            nums[i] = sc.nextInt();
        }
        bt(0, new boolean[n], 0);
        String s = "";
        for(int i = 0; i < keys.length; i++){
        	if(keys[i]){
        		s+= nums[i] + " ";
        	}
        }
        s += "sum:" + maxFound;
        System.out.println(s);
    }
}    
    public static void bt(int x, boolean[] flags, int trueCount){
        if(x > max){
            return;
        }
         maxFound = Math.max(x, maxFound);
         if(maxFound == x){keys = Arrays.copyOf(flags, flags.length);}
        if(x == max || trueCount == nums.length || found){
            found = true;
            return;
        }
       
        for(int i = 0; i < flags.length; i++){
            if(!flags[i]){
                flags[i] = true;
                bt(x+nums[i], flags, trueCount+1);
                flags[i] = false;
            }
        }
    }
}